package com.bap.ele.workbench.ui.views.model;

import java.util.LinkedList;
import java.util.List;

/**
 * 
 * @author zhangxinchao
 * @date Apr 10, 2009
 */
public class CourseTreeNode implements IContentNode {

	private String name;

	private IContentNode parent;

	private List<IContentNode> children;

	public CourseTreeNode(String name) {
		this.name = name;
		children = new LinkedList<IContentNode>();
	}

	/*
	 * (non-Javadoc)
	 * @see com.bap.ele.workbench.module.IContentObject#addChild(com.bap.ele.workbench.module.IContentObject)
	 */
	public void addChild(IContentNode child) {
		System.out.println("--node="+child.getName());
		children.add(child);
	}

	/*
	 * (non-Javadoc)
	 * @see com.bap.ele.workbench.module.IContentObject#getChildren()
	 */
	public IContentNode[] getChildren() {
		return (IContentNode[]) children.toArray(new IContentNode[children
				.size()]);
	}

	/*
	 * (non-Javadoc)
	 * @see com.bap.ele.workbench.module.IContentObject#getName()
	 */
	public String getName() {
		return name;
	}

	/*
	 * (non-Javadoc)
	 * @see com.bap.ele.workbench.module.IContentObject#getParent()
	 */
	public IContentNode getParent() {
		return this.parent;
	}

	/*
	 * (non-Javadoc)
	 * @see com.bap.ele.workbench.module.IContentObject#hasChildren()
	 */
	public boolean hasChildren() {
		return this.children.size() > 0;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.bap.ele.workbench.module.IContentObject#removeChild(com.bap.ele.workbench
	 * .module.IContentObject)
	 */
	public void removeChild(IContentNode child) {
		this.children.remove(child);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
	 */
	public Object getAdapter(Class adapter) {
		return null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.bap.ele.workbench.module.IContentObject#setParent(com.bap.ele.workbench
	 * .module.IContentObject)
	 */
	public void setParent(IContentNode parent) {
		this.parent = parent;
	}
	
	/*
	 * (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString(){
		return name;
	}

	/*
	 * (non-Javadoc)
	 * @see com.bap.ele.workbench.module.IContentNode#isLeaf()
	 */
	public boolean isLeaf() {
		return false;
	}

	public String getType() {
		// TODO Auto-generated method stub
		return null;
	}

}
